package com.situ.admin.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.situ.admin.bean.APIResult;
import com.situ.admin.utils.UploadUtil;

@RestController
@CrossOrigin(origins = { "*" })
public class UploadController {

	// 从配置文件中读取一个值
	@Value("${spring.servlet.multipart.location}")
	private String path;

	@PostMapping("/api/upload")
	public APIResult upload(MultipartFile file) {

		String filename = UploadUtil.save(file, path);
		return APIResult.ok(filename);
	}

}
